﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;

namespace AfterDash
{
    class Logger
    {
        private FileStream logFile;

        public Logger()
        {
            logFile = new FileStream("Log.txt", FileMode.Append);
        }

        public void WriteLog(string[] trackdata)
        {
            logFile.Write(GetBytes(trackdata[0] + ","), 0, GetBytes(trackdata[0] + ",").Length);
            logFile.Write(GetBytes(trackdata[1] + ","), 0, GetBytes(trackdata[1] + ",").Length);
            logFile.Write(GetBytes(trackdata[2] + ","), 0, GetBytes(trackdata[2] + ",").Length);
            logFile.Write(GetBytes(trackdata[3] + ","), 0, GetBytes(trackdata[3] + ",").Length);
            logFile.Write(GetBytes(trackdata[4] + ","), 0, GetBytes(trackdata[4] + ",").Length);
            logFile.Write(GetBytes(trackdata[5] + ","), 0, GetBytes(trackdata[5] + ",").Length);
            logFile.Write(GetBytes("\n"), 0, GetBytes("\n").Length);
        }

        private byte[] GetBytes(string toConvert)
        {
            byte[] returnVal = new byte[toConvert.Length];
            char[] chars = toConvert.ToArray();
            for (int i = 0; i < chars.Length; i++)
            {
                returnVal[i] = Convert.ToByte(chars[i]);
            }

            return returnVal;
        }

        public void EndLog()
        {
            logFile.Close();
        }
    }
}
